package com.cmxh.shipper.config;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * 前端发送给后端的所有请求 都会先经过过滤器 然后再到controller请求
 */
@Component
public class LuanMaFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器");



       // 前端如果发送的是post请求 而且请求中有乱码
        // 我们把前端发送过来的请求中文字使用UTF-8进行重新编码
        servletRequest.setCharacterEncoding("UTF-8");

        //servletResponse.setCharacterEncoding("UTF-8");
        // 让请求继续往下走
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
